package com.bridgeintelligent.tag.scene.controller;

import com.bridgeintelligent.tag.scene.api.IHelpService;
import com.bridgeintelligent.tag.scene.api.dto.SceneDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @description
 * @author: grp 2021-03-29 14:22
 **/
@Api(tags = "帮助中心")
@RestController
@AllArgsConstructor
@RequestMapping("api/help")
@Validated
public class HelpController {

    private IHelpService helpService;

    @ApiOperation(value = "文件名称", notes = "帮助中心")
    @GetMapping("/getFileName")
    public SceneDto getFileName() {
        return SceneDto.success(helpService.getFileName());
    }

    @ApiOperation(value = "下载上次上传的文件", notes = "帮助中心")
    @GetMapping("/downLoad")
    public void downLoad(HttpServletResponse response, HttpServletRequest request) {
        helpService.downLoad(response,request);
    }

    @ResponseBody
    @ApiOperation(value = "上传", notes = "帮助中心")
    @PostMapping(path="upload")
    public SceneDto upload(@RequestParam("file") MultipartFile file) {
        String url = helpService.upload(file);
        return SceneDto.success();
    }
}
